<?php
namespace Account;
class OrderController extends BaseController{
	public function index(){
		$this->showlist();
	}
	
	public function showlist(){
		global $G,$lang;
		if ($this->checkFormSubmit()) {
			
		}else {
			
			$pagesize = 10;
			$condition = array('uid'=>$this->uid);
			$status = htmlspecialchars($_GET['status']);
			if ($status) $condition['order_status'] = $status;
			$totalnum  = order_get_num($condition);
			$pagecount = $totalnum < $pagesize ? 1 : ceil($totalnum/$pagesize);
			$orderlist = order_get_page($condition, $G['page'], $pagesize);
			if ($orderlist) {
				$orderids = $comma = '';
				$datalist = array();
				foreach ($orderlist as $order){
					$orderids.= $comma.$order['order_id'];
					$comma = ',';
					$datalist[$order['order_id']] = $order;
				}
				$goodslist = $datalist;
				
				if ($orderids) {
					$goodslist = order_get_goods_list(array('uid'=>$this->uid, 'order_id'=>array('IN', $orderids)));
					if ($goodslist) {
						foreach ($goodslist as $goods){
							$orderlist[$goods['order_id']]['goods'][$goods['goods_id']] = $goods;
						}
					}
				}
				unset($orderids, $comma, $datalist, $goodslist, $goods);
			}
			include template('order_list');
		}
	}
}